package com.blog.boot.service.index.service.impl;

import com.blog.boot.api.entity.UserEntity;
import com.blog.boot.api.index.service.TestService;
import com.blog.boot.api.system.Role;
import com.mongodb.DBCollection;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.BsonDocument;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class TestServiceImpl implements TestService {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public String testService(String name) {
        Role role = new Role();
        role.setRoleKey(name);
        role.setRoleValue("root");
        role.setDescription("拥有至高无上的权限");
        Set<String> set = new HashSet<>();
        /*
        *  user:root
        *  user:root
        *
        * */
        set.add("0");
        set.add("1");
        set.add("2");
        set.add("3");
        /*role.setPermissions(set);
        mongoTemplate.save(role);*/
        /*Query query = new Query(Criteria.where("title").is(name));
        UserEntity testConllection = mongoTemplate.findOne(query, UserEntity.class, "testConllection");
        System.out.println(testConllection.toString());*/
        return "成功";
    }
}
